/*
   Copyright 2009 Bégaudeau Stéphane

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */

package faneclipse.views;

import java.util.ArrayList;
import java.util.List;

/**
 * @author BEGAUDEAU stephane
 */
public class TreeParent extends TreeObject {
	/**
	 * The children of the object.
	 */
	private List<TreeObject> children;
	
	/**
	 * The constructor.
	 * @param name The name of the object.
	 */
	public TreeParent(final String name) {
		super(name);
		children = new ArrayList<TreeObject>();
	}

	/**
	 * @param child A new child.
	 */
	public final void addChild(final TreeObject child) {
		children.add(child);
		child.setParent(this);
	}

	/**
	 * @param child A child to remove.
	 */
	public final void removeChild(final TreeObject child) {
		children.remove(child);
		child.setParent(null);
	}

	/**
	 * @return the children of the object.
	 */
	public final TreeObject[] getChildren() {
		return (TreeObject[]) children.toArray(new TreeObject[children.size()]);
	}

	/**
	 * @return A boolean showing if the object has children.
	 */
	public final boolean hasChildren() {
		return children.size() > 0;
	}

}
